import BaseMapper from "./BaseMapper";
import SqlStatement from "../sql/SqlStatement";
import SystemUser from "../entity/SystemUser";

export default class SystemUserMapper implements BaseMapper<SystemUser> {
    async deleteById(statement: SqlStatement) {
        return await statement.run();
    }

    async insert(statement: SqlStatement) {
        return await statement.run();
    }

    async page(statement: SqlStatement) {
        const rows = await statement.all();
        const total = await statement.count();
        return {
            rows,
            total: total.counter
        }
    }

    async updateById(statement: SqlStatement) {
        return await statement.run();
    }

    async selectByUsername(username: string) {
        const sql = `SELECT * FROM system_user WHERE username = '${username}'`;
        const statement = new SqlStatement(sql);
        const user = await statement.get();
        return user;
    }

    async selectByMobile(mobile: string) {
        const sql = `SELECT * FROM system_user WHERE mobile = '${mobile}'`;
        const statement = new SqlStatement(sql);
        const user = await statement.get();
        return user;
    }
}
